import { createRouter, createWebHashHistory } from "vue-router";
const routes = [
  {
    path: "/",
    component: () => import("../views/layout/Layout.vue"),
    children: [
      { path: "/home", name: "home", component: () => import("../views/main/Home.vue") },
      { path: "/about", name: "about", component: () => import("../views/main/About.vue") },
      { path: "/user", name: "user", component: () => import("../views/user/User.vue") },
      { path: "/canvas/Screenshot", name: "/canvas/Screenshot", component: () => import("../views/canvas/Screenshot.vue") },
      { path: "/pulldown", name: "pulldown", component: () => import("../views/bscroll/Pulldown.vue") },
      { path: "/fund", name: "fund", component: () => import("../views/finance/Fund.vue") },
      { path: "/finance/ChartTest", name: "/finance/ChartTest", component: () => import("../views/finance/ChartTest.vue") },
      { path: "/VirtualTable", name: "/VirtualTable", component: () => import("../views/user/VirtualTable.vue") },
      { path: "/:pathMatch(.*)", component: () => import("../views/error/NotFound.vue") },
      { path: "/404", component: () => import("../views/error/NotFound.vue") },
    ],
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/login/Login.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
router.beforeEach((to, from, next) => {
  // console.log(window.getCookie("name"));
  // next();
  // console.log(to);
  // if (from.path !== "/Home") {
  //   next({ name: "Home" });
  // }else{

  // }

  if (!window.getCookie("name") && to.path !== "/login") {
    next({ path: "/login" });
  } else {
    if (to.path === "/") {
      next({ path: "/home" });
    } else {
      next();
    }
  }

  // } else {
  //   console.log("login");
  //   // next({ path: "/login" });
  //   next({ path: "/home" });
  // }
});
export default router;
